<template>
  <div>
    <el-card class="box-card">
      <el-select v-model="query.truckTypeId" class="numInp" placeholder="请选择车辆类型">
        <el-option label="4.2米箱式货车" value="1575066321985286145" />
        <el-option label="12.8米箱式货车" value="1575257460197634049" />
        <el-option label="6.8米箱式货车" value="1575257668885229569" />
      </el-select>
      <el-input v-model="query.licensePlate" placeholder="请输入车牌号码" class="numInp" />
      <el-button class="btn" type="primary" @click="getCarPageList">搜索</el-button>
      <el-button class="btn" @click="reset">重置</el-button>
    </el-card>
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="1">全部</el-menu-item>
      <el-menu-item index="2">可用</el-menu-item>
      <el-menu-item index="3">停用</el-menu-item>
    </el-menu>
    <el-card class="box-card box-card2">
      <el-button type="primary" @click="add">新增车辆</el-button>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column type="index" label="序号" />
        <el-table-column prop="licensePlate" label="车牌号码" />
        <el-table-column prop="truckTypeName" label="车辆类型" />
        <el-table-column prop="driverNum" label="司机数量" />
        <el-table-column prop="workStatus" label="车辆状态">
          <template v-slot="{ row }">
            <span>{{ row.workStatus === 0? '停用' : '启用' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="deviceGpsId" label="GPS设备ID" />
        <el-table-column prop="allowableLoad" label="实载重量（T）" />
        <el-table-column prop="allowableVolume" label="实载体积（方）" />
        <el-table-column label="操作" width="260">
          <template v-slot="{ row }">
            <el-button type="text" @click="look">查看详情</el-button>
            <el-button v-if="row.workStatus === 0" type="text" @click="start">启用</el-button>
            <el-button v-else type="text" style="color:red" @click="stop">停用</el-button>
            <el-button type="text" @click="pei">配置司机</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="page"
        :current-page.sync="query.page"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script>
import { getCarPageListAPI } from '@/api/carList'
import { Message } from 'element-ui'
export default {
  name: 'CarList',
  data() {
    return {
      tableData: [],
      query: {
        page: 1,
        pageSize: 10,
        licensePlate: '',
        truckTypeId: '',
        workStatus: ''
      },
      total: 1,
      activeIndex: '1'
    }
  },
  created() {
    this.getCarPageList()
  },
  methods: {
    async getCarPageList() {
      const result = await getCarPageListAPI(this.query)
      this.tableData = result.data.data.items
      this.total = +result.data.data.counts
    },
    handleSizeChange(pageSize) {
      this.query.pageSize = pageSize
      this.getCarPageList()
    },
    handleCurrentChange(page) {
      this.query.page = page
      this.getCarPageList()
    },
    look() {
      Message.error('不给看^_^')
    },
    start() {
      Message.error('不给启^_^')
    },
    stop() {
      Message.error('不给停^_^')
    },
    pei() {
      Message.error('不给配^_^')
    },
    add() {
      Message.error('不给增^_^')
    },
    reset() {
      this.query.licensePlate = ''
      this.query.truckTypeId = ''
      this.getCarPageList()
    },
    async handleSelect(index) {
      console.log(index)
      if (index === '1') {
        this.query.workStatus = ''
        const result = await getCarPageListAPI(this.query)
        console.log(result)
        this.tableData = result.data.data.items
        this.total = +result.data.data.counts
      } else if (index === '2') {
        this.query.workStatus = 1
        const result = await getCarPageListAPI(this.query)
        console.log(result)
        this.tableData = result.data.data.items
        this.total = +result.data.data.counts
      } else if (index === '3') {
        this.query.workStatus = 0
        const result = await getCarPageListAPI(this.query)
        console.log(result)
        this.tableData = result.data.data.items
        this.total = +result.data.data.counts
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.numInp{
  width: 20%;
  margin-right: 20px;
}
.btn{
  margin-right: 20px;
  width: 10%;
}
.el-menu-demo{
  margin-top: 20px;
}
.box-card2{
  margin-top: 20px;
}
.page{
  text-align: center;
  margin-top: 30px;
}
</style>
